﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using TERP.WaterClient.Common;

namespace TERP.WaterClient.Entities.Auth
{
	public class GroupCollection : List<Group>
	{
		private DataTable _dtbData;

		public GroupCollection()
            : base()
		{
        }

		/// <summary>
		/// 
		/// </summary>
		public DataTable DataTableGroup
		{
			get
			{
				return _dtbData;
			}
			set {
				_dtbData = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="soCode"></param>
		/// <returns></returns>
		public Group FindGroup(string groupCode)
		{
			foreach (Group grp in this)
			{
				if (grp.GroupCode.Equals(groupCode))
					return grp;
			}
			return null;
		}

		/// <summary>
		/// 
		/// </summary>
		public void FillToDataTable()
		{
			_dtbData = new DataTable(DbTable.Tbl_Group);
			_dtbData.Columns.AddRange(new DataColumn[] { 
		        new DataColumn(TblGroup.Group_Code,typeof(string)),
		        new DataColumn(TblGroup.Group_Name,typeof(string))
			});
			DataRow dtRow;
			foreach (Group grp in this)
			{
				dtRow = _dtbData.NewRow();
				dtRow[TblGroup.Group_Code] = grp.GroupCode;
				dtRow[TblGroup.Group_Name] = grp.GroupName;
				//
				_dtbData.Rows.Add(dtRow);
			}
			_dtbData.AcceptChanges();
		}
	}
}
